package com.shop.controller;

import com.mybatisflex.core.paginate.Page;
import com.shop.entity.ShopProductSku;
import com.shop.service.ShopProductSkuService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 * 商品sku 控制层。
 *
 * @author 彭新才
 * @since 2024-10-12
 */
@RestController
@Tag(name = "商品sku接口")
@RequestMapping("/shopProductSku")
public class ShopProductSkuController {

    @Autowired
    private ShopProductSkuService shopProductSkuService;

    /**
     * 添加商品sku。
     *
     * @param shopProductSku 商品sku
     * @return {@code true} 添加成功，{@code false} 添加失败
     */
    @PostMapping("save")
    @Operation(summary = "保存商品sku")
    public boolean save(@RequestBody @Parameter(name = "商品sku") ShopProductSku shopProductSku) {
        return shopProductSkuService.save(shopProductSku);
    }

    /**
     * 根据主键删除商品sku。
     *
     * @param id 主键
     * @return {@code true} 删除成功，{@code false} 删除失败
     */
    @DeleteMapping("remove/{id}")
    @Operation(summary = "根据主键删除商品sku")
    public boolean remove(@PathVariable @Parameter(name = "商品sku主键") Serializable id) {
        return shopProductSkuService.removeById(id);
    }

    /**
     * 根据主键更新商品sku。
     *
     * @param shopProductSku 商品sku
     * @return {@code true} 更新成功，{@code false} 更新失败
     */
    @PutMapping("update")
    @Operation(summary = "根据主键更新商品sku")
    public boolean update(@RequestBody @Parameter(name = "商品sku主键") ShopProductSku shopProductSku) {
        return shopProductSkuService.updateById(shopProductSku);
    }

    /**
     * 查询所有商品sku。
     *
     * @return 所有数据
     */
    @GetMapping("list")
    @Operation(summary = "查询所有商品sku")
    public List<ShopProductSku> list() {
        return shopProductSkuService.list();
    }

    /**
     * 根据商品sku主键获取详细信息。
     *
     * @param id 商品sku主键
     * @return 商品sku详情
     */
    @GetMapping("getInfo/{id}")
    @Operation(summary = "根据主键获取商品sku")
    public ShopProductSku getInfo(@PathVariable @Parameter(name = "商品sku主键") Serializable id) {
        return shopProductSkuService.getById(id);
    }

    /**
     * 分页查询商品sku。
     *
     * @param page 分页对象
     * @return 分页对象
     */
    @GetMapping("page")
    @Operation(summary = "分页查询商品sku")
    public Page<ShopProductSku> page(@Parameter(name = "分页信息") Page<ShopProductSku> page) {
        return shopProductSkuService.page(page);
    }

}
